home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / MEMMON_F / MMAED.C < prev    next >
Text File  |  1990-03-02  |  5KB  |  209 lines

  1. /*
  2.  * mmaed.c: graphics driver for AED 1024.
  3.  *
  4.  *  The AED is a 1024 x 768 x 8 color display with an 8+8+8 bit lookup table.
  5.  *
  6.  *  For reasons of speed, this driver writes all blocks one pixel high
  7.  *  using a runlength encoding.  Hardware zoom (vertically only) is used
  8.  *  to make the display look reasonable.  This all works well and does
  9.  *  speed things up quit a bit, but it means we can't write any text,
  10.  *  so there's no legend on the display.
  11.  */
  12.  
  13. #include <varargs.h>
  14. #include "memmon.h"
  15.  
  16. hidden novalue aedcmd Params((/*varargs*/));
  17.  
  18. #define VSize 768            /* vertical screen size */
  19. #define HSize 1024            /* horizontal screen size */
  20. #define EndRun() if(runaddr)putchar(runaddr=0)  /* end a run of pixels */
  21.  
  22. static runaddr = 0;            /* curr addr if pixel run in progress */
  23.  
  24. /*
  25.  * devsetup() - set globals to device-dependent values.
  26.  */
  27. novalue devsetup()
  28.    {
  29.    granularity = 4;
  30.    width = HSize;
  31.    height = VSize;
  32.    textrow = 0;                /* no legend */
  33.    textsep = 0;                /* so no separating line */
  34.    memrow = 16;
  35.    }
  36.  
  37. /*
  38.  * devinit() - initialize for graphics output.
  39.  */
  40. novalue devinit()
  41.    {
  42.    static char obuf[BUFSIZ];        /* small buffer for smoother output */
  43.  
  44.    if (height != VSize || width != HSize || textrow > 0) {
  45.       fprintf(stderr, "%s: -h, -w, -L ignored\n", progname);
  46.       height = VSize;
  47.       width = HSize;
  48.       textrow = 0;
  49.       }
  50.    if (memrow > 16) {
  51.       fprintf(stderr, "%s: -M limited to 16\n", progname);
  52.       memrow = 16;            /* hardware limit */
  53.       }
  54.    litout();                /* set literal output mode if a tty */
  55.    setbuf(stdout, obuf);        /* set small, local buffer */
  56.    fputs("\033SEN18D88", stdout);    /* set encoding mode to binary */
  57.    aedcmd("gii", 0, 767);        /* set normal window boundaries */
  58.    aedcmd("4bbbbbb", Unmarked + C_Blink, 0, 0, 0, 20, 20);
  59.                     /* blink C_Blink with black */
  60.    }
  61.  
  62. /*
  63.  * devmap() - load color map into device.
  64.  */
  65. novalue devmap()
  66.    {
  67.    int i;
  68.  
  69.    EndRun();
  70.    aedcmd("Kbb", 0, MapSize);
  71.    for (i = 0; i < MapSize; i++)  {
  72.       putchar(cmap[i].red);
  73.       putchar(cmap[i].green);
  74.       putchar(cmap[i].blue);
  75.       }
  76.    }
  77.  
  78. /*
  79.  * devflood(c) - fill screen with color c.
  80.  */
  81. novalue devflood(c)
  82. int c;
  83.    {
  84.    EndRun();
  85.    aedcmd("Ebb", 1, memrow);        /* set zoom for y scaling (only!) */
  86.    aedcmd("[b", c);            /* set background color */
  87.    aedcmd("~");                /* erase screen (kills scaling) */
  88.    aedcmd("Ebb", 1, memrow);        /* reset scaling */
  89.    }
  90.  
  91. /*
  92.  * devpaint(start, n, color, b) - paint n pixels in given color.
  93.  *  If b >= 0, the last pixel is to be that color instead (for a border)
  94.  */
  95. novalue devpaint(s, n, c, b)
  96. word s, n;
  97. int c, b;
  98.    {
  99.    if (runaddr && runaddr != s)
  100.       putchar(runaddr = 0);
  101.    if (!runaddr)  {
  102.       aedcmd("Qx", s % HSize, VSize - 1 - s / HSize);
  103.       aedcmd("s");
  104.       }
  105.    runaddr = s + n;
  106.    if (b >= 0)
  107.       n--;
  108.    while (n > 254)  {
  109.       putchar(254);
  110.       putchar(c);
  111.       n -= 254;
  112.       }
  113.    if (n > 0)  {
  114.       putchar(n);
  115.       putchar(c);
  116.       }
  117.    if (b >= 0)  {
  118.       putchar(1);
  119.       putchar(b);
  120.       }
  121.    }
  122.  
  123. /*
  124.  * devtext(string, row, col, fgcolr, bgcolr) - don't output text.
  125.  *  (We can't output any text due to the mode we've put the AED in.)
  126.  *  (So, with textrow=0, this shouldn't ever be called, but is needed to link.)
  127.  */
  128.  
  129. /*ARGSUSED*/
  130. novalue devtext(s, r, c, f, b)
  131. char *s;
  132. int r, c, f, b;
  133.    {
  134.    }
  135.  
  136. /*
  137.  * devsnap() - batch mode snapshot; no action needed here.
  138.  */
  139. novalue devsnap()
  140.    {
  141.    }
  142.  
  143. /*
  144.  * devflush() - flush output.
  145.  */
  146. novalue devflush()
  147.    {
  148.    EndRun();
  149.    fflush(stdout);
  150.    }
  151.  
  152. /*
  153.  * devterm() - terminate graphics.
  154.  */
  155. novalue devterm()
  156.    {
  157.    EndRun();
  158.    aedcmd("Gs", "3DNNN");        /* reset encoding */
  159.    aedcmd("\r");            /* exit graphics mode */
  160.    }
  161.  
  162. /*
  163.  * aedcmd(s, args) - output command to the AED.
  164.  *  s is a string specifying the command format a la printf.  The first
  165.  *  character (or two chars if first is '+') are the AED command.
  166.  *  Additional characters specify formats for outputting additional
  167.  *  arguments (see below).
  168.  */
  169.  
  170. /*VARARGS1*/
  171. static novalue aedcmd (s, va_alist)
  172. char *s;
  173. va_dcl
  174.    {
  175.    va_list ap;
  176.    char c;
  177.    unsigned int n, x, y;
  178.  
  179.    va_start(ap);
  180.    if (putchar(*s++) == '+')
  181.       putchar(*s++);
  182.    while (c = *s++)
  183.       switch (c)  {            /* Output formats for add'l args:  */
  184.          case 'b':            /* b - single byte unaltered */
  185.          case 'c':            /* c - single char unaltered */
  186.             n = va_arg(ap, int);
  187.             putchar(n);
  188.             break;
  189.          case 'i':            /* i - 16-bit integer as two bytes */
  190.             n = va_arg(ap, int);
  191.             putchar(n>>8);
  192.             putchar(n);
  193.             break;
  194.          case 's':            /* s - string terminated by '\0' */
  195.             fputs(va_arg(ap, char*), stdout);
  196.             break;
  197.          case 'x':            /* x - two args give x and y coords */
  198.             x = va_arg(ap, int);
  199.             y = va_arg(ap, int);
  200.             putchar(((x >> 4) & 0xF0) | (y >> 8));
  201.             putchar(x);
  202.             putchar(y);
  203.             break;
  204.          default:            /* unrecognized - just echoed */
  205.             putchar(c);
  206.          }
  207.    va_end(ap);
  208.    }
  209.